package com.samba.entites;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * cet entite sert a gerer les types de projets a savoir : (court terme , moyen
 * terme , longterme ) car les preteurs aimerai savoir la dureee de leur prets
 * 
 * @author samba
 * 
 */
@Entity
@Table(name = "TABLE_TYPES")
@NamedQueries({
		@NamedQuery(name = "findAllTypes", query = "SELECT type FROM Type AS type"),
		@NamedQuery(name = "findAllTypeById", query = "SELECT t FROM Type AS t WHERE t.id = :id") 
		})
public class Type implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int id;
	private String label;

	
	private Set<Projet> projetCollection;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	
	@OneToMany(mappedBy = "typeFk")
	public Set<Projet> getProjetCollection() {
		return projetCollection;
	}

	public void setProjetCollection(Set<Projet> projetCollection) {
		this.projetCollection = projetCollection;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		result = prime * result + ((label == null) ? 0 : label.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Type other = (Type) obj;
		if (id != other.id)
			return false;
		if (label == null) {
			if (other.label != null)
				return false;
		} else if (!label.equals(other.label))
			return false;
		return true;
	}
}
